package com.data.csv.service;

import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.Task;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
@Slf4j
public class TaskService implements CommandLineRunner {

    @Resource
    private DataService dataService;
    @Value("${csv.cron:0 0/2 * * * ? }")
    private String corn;


    /**
     * 定时任务执行 每月一次
     */
    @Override
    public void run(String... args) throws Exception {
        dataService.task();
        CronUtil.schedule(corn, (Task) () -> dataService.task());
        CronUtil.start();
    }
}
